From: Colin Walters Date: Mon, 31 Jul 2017 14:05:04 +0000 (-0400) Subject: tests/lzma: Fix off-by-one in buffer size X-Git-Tag: archive/raspbian/2022.1-3+rpi1~1^2~4^2~33^2~56 X-Git-Url: https://dgit.raspbian.org/%22http:/www.example.com/cgi/%22https:/%22bookmarks:///%22http:/www.example.com/cgi/%22https:/%22bookmarks:/?a=commitdiff_plain;h=fe8938227e767ab85bc4f1d599032165aa2bf133;p=ostree.git tests/lzma: Fix off-by-one in buffer size Coverity spotted that we had an off-by-one here since we were using `i+1`. Fix this by adding a `-1` to the bounds check. Also use `sizeof()` to ensure the data and size are coupled. Coverity CID: 1452207 Closes: #1037 Approved by: jlebon --- diff --git a/tests/test-lzma.c b/tests/test-lzma.c index b3487ee3..559e9ad4 100644 --- a/tests/test-lzma.c +++ b/tests/test-lzma.c @@ -79,13 +79,12 @@ static void test_lzma_random (void) { gssize i; - const guint32 buffer_size = 4096 + 1; - guint8 buffer[buffer_size]; + guint8 buffer[4096]; g_autoptr(GRand) r = g_rand_new (); - for (i = 0; i < buffer_size; i++) + for (i = 0; i < sizeof(buffer); i++) buffer[i] = g_rand_int (r); - for (i = 2; i <= buffer_size; i *= 2) + for (i = 2; i < (sizeof(buffer) - 1); i *= 2) { helper_test_compress_decompress (buffer, i - 1); helper_test_compress_decompress (buffer, i);